import axios from 'axios'
//创建一个axios实例对像
const service = axios.create({
  baseURL: '/mock',
  timeout: 5000 //设置请求超时    
})
//创建请求拦截器
service.interceptors.request.use(
  config => {
    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)
//创建响应拦截器
service.interceptors.response.use(
  response => {
    const result = response.data
    if (result.status === 2000) {
      return result
    } else {
      return Promise.reject(new Error('请求失败'))
    }
  },
  error => {
    return Promise.reject(error)
  }
)
export default service
